var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var router =express.Router()
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();
router.get('/detail/:id',function(req,res){
var reqAttributes={
'originalUrl':req.originalUrl,

'hostname':req.hostname,
'ip':req.ip,
'method':req.method,
'path':req.path,
'protocol':req.protocol,
'secure':req.secure,
'xhr':req.xhr,
'params':req.params,



}

res.send(reqAttributes)

})
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  next(createError(404));
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});var express = require('express');
var router = express.Router();
router.get('/product', function(req, res) {
    var reqAttributes = {
        'originalUrl': req.originalUrl, // 获取路由配置的 URL
        'hostname': req.hostname, // 获取用户请求的域名
        'ip': req.ip, // 获取用户请求的 IP 地址
       'method': req.method, // 获取用户请求的方法
        'path': req.path, // 获取 URL 请求中的路径
        'protocol': req.protocol, // 获取客户端请求的协议
      'secure': req.secure, // 判断是否为 HTTPS 请求
        'xhr': req.xhr, // 判断是否是 AJAX 请求
        'query': req.query // 获取 URL 查询字符串部分的参数
    }
    res.send(reqAttributes);
});
module.exports = router;


// 删除下面这行！
// app.listen(3006, function(err) {
//   console.log('Server running at http://127.0.0.1:3005 /');
// });

module.exports = app;